//
//  CampusDetailTitleView.m
//  ShowYork
//
//  Created by hxh on 2021/3/26.
//  Copyright © 2021 hxh. All rights reserved.
//

typedef void(^doneBlock)(void);
#import "CampusDetailTitleView.h"

@interface CampusDetailTitleView ()
@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,strong)UIImageView *moreIcon;
@property (nonatomic,strong)UILabel *moreLb;
@property (nonatomic,strong)UIButton *moreBtn;

@property (nonatomic,copy)NSString *title;
@property (nonatomic,copy)doneBlock done;
@property (nonatomic,strong)UIView *line;

@end

@implementation CampusDetailTitleView

- (instancetype)initWithTitle:(NSString *)title completeBlock:(void (^)(void))completeBlock{
    if (self = [super init]) {
        self.title = title;
        [self setUI];
        if (completeBlock) {
            self.done = ^{
                completeBlock();
            };
        }
    }
    return self;
}

- (void)setUI{
    
    self.frame = CGRectMake(0, 0, kScreenW, 52);
    self.backgroundColor = UIColor.whiteColor;
    
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = RGBA(240, 240, 240, 1);
    [self addSubview:self.line];
    
    self.titleLb = [[UILabel alloc]init];
    
    self.titleLb.text = self.title;
    self.titleLb.textColor = C51;
    self.titleLb.font = [UIFont boldSystemFontOfSize:18];

    [self addSubview:self.titleLb];

    self.moreLb = [[UILabel alloc]init];
    self.moreLb.text = @"更多";
    self.moreLb.textColor = C153;
    self.moreLb.font = font(12);
    [self addSubview:self.moreLb];
    
    self.moreIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"campus_more_tag"]];
    [self addSubview:self.moreIcon];
    
    self.moreBtn = [[UIButton alloc]init];
    [self.moreBtn addTarget:self action:@selector(moreMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.moreBtn];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(8);
    }];
    
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.left.equalTo(self).offset(20);
    }];
    [self.moreIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-20);
        make.centerY.equalTo(self.titleLb);
    }];
    [self.moreLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.moreIcon.mas_left);
        make.centerY.equalTo(self.titleLb);
    }];
    [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self);
        make.width.mas_equalTo(100);
    }];
}

- (void)moreMethod{
    self.done();
}
- (void)setShowMore:(BOOL)showMore{
    _showMore = showMore;
    self.moreLb.hidden = !showMore;
    self.moreBtn.hidden = !showMore;
    self.moreIcon.hidden = !showMore;
}

@end
